// const router = require("../routers/m1")
const Router = require("koa-router");
const requireDirectory = require("require-directory");
// requireDirectory(module,`${process.cwd()}/routers/m1`,{visit:loadRouters});
const render = require("koa-art-template")
const static = require("koa-static");
const bodyParser = require("koa-bodyparser")
function initManage(app){
    // app.use(router.routes())
    // 加载/routers/m1下的文件时，会触发loadRouters函数
    app.use(bodyParser())//放在上面
    requireDirectory(module,`${process.cwd()}/routers`,{
        visit:loadRouters
    })
    render(app,{
        root:`${process.cwd()}/views`,
        extname:'.html',
        debug:process.env.NODE_ENV !== 'production'
    })
    function loadRouters(obj){
        console.log(obj);
        if(obj instanceof Router){
            app.use(obj.routes())
        }
    }
    app.use(static(`${process.cwd()}/images`))      //
    app.use(static(`${process.cwd()}/static`))      //
    
}
module.exports = initManage